package acm;
import java.util.Scanner;

public class T5226 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String inorder=sc.nextLine();
        String postorder=sc.nextLine();
        String preorder = buildPreorder(inorder, postorder, 0, 0, inorder.length());
        System.out.println(preorder);
    }

    public static String buildPreorder(String inorder,String postorder,int inorderStart,int postorderStart,int len){
        if (len<1){
            return "";
        }
        char root=postorder.charAt(postorderStart+len-1);
        if (len==1){
            return root+"";
        }

        int rootIndex=inorderStart;
        for (int i = inorderStart; i < inorder.length(); i++) {
            if (root==inorder.charAt(i)){
                rootIndex=i;
                break;
            }
        }
        String left = buildPreorder(inorder, postorder, inorderStart, postorderStart, rootIndex - inorderStart);
        String right = buildPreorder(inorder, postorder, rootIndex + 1, postorderStart+rootIndex-inorderStart, inorderStart+len - rootIndex-1);
        return root+left+right;
    }
}

